/*
ID: simplyz2
LANG: C
TASK: milk
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LEN 5001
#define Min(a,b) ((a)<(b) ? (a) : (b))
int total, num;
struct Farm {
	int price, amount;
} farms[MAX_LEN];

int
compare(const void *arg1, const void *arg2)
{
	return ((struct Farm *)arg1)->price - ((struct Farm *)arg2)->price;
}

void
solve()
{
	int i, tmp, rt = 0;
	for(i=0; i<num&&total>0; i++) {
		tmp = Min(farms[i].amount, total);
		rt += (farms[i].price * tmp);
		total -= tmp;
	}
	printf("%d\n", rt);
}

int
main(int argc, char **argv)
{
	int i;
	freopen("milk.in", "r", stdin);
	freopen("milk.out", "w", stdout);
	while(scanf("%d %d", &total, &num) != EOF) {
		for(i=0; i<num; i++) 
			scanf("%d %d", &farms[i].price, &farms[i].amount);
		qsort(farms, num, sizeof(struct Farm), compare);
		solve();
	}
	return 0;
}
